package cn.fl.ref.crbaseinfo.transform;

import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.List;

import cn.cmm.base.framework.utils.CollectionUtils;
import cn.cmm.base.framework.utils.DecimalUtils;
import cn.fl.ref.crbaseinfo.vo.CrAstRltvInfoVO;
import fl.ref.crbaseinfo.dto.CrAstRltvInfoDTO;

public class CrAstRltvInfoVOTransform {
	/**
	 * 分转元
	 * @param number
	 * @return
	 */
	public static BigDecimal fenToYuan(BigDecimal number){
		if(number!=null&&number!=new BigDecimal(0)){
			return number.divide(new BigDecimal(100), 2, BigDecimal.ROUND_HALF_UP);
		}
		return null;
	}
	
	/**
	 * 元转分
	 * @param number
	 * @return
	 */
	public static BigDecimal yuanToFen(BigDecimal number){
		if(number!=null&&number!=new BigDecimal(0)){
			return number.multiply(new BigDecimal(100));
		}
		return null;
	}
	
	/**
	 * DTO 转  VO
	 * @param dto
	 * @return
	 */
	public static CrAstRltvInfoVO toVO(CrAstRltvInfoDTO dto) {
		CrAstRltvInfoVO  vo = null;
		if (dto != null) { 
			vo = new CrAstRltvInfoVO();
			
			vo.setId(dto.getId());
			vo.setCrId(dto.getCrId());
			vo.setAstId(dto.getAstId());
			vo.setAstNm(dto.getAstNm());
			vo.setPdId(dto.getPdId());
			vo.setPdNm(dto.getPdNm());
			//分转元
			vo.setUseLmt(fenToYuan(dto.getUseLmt()));
			vo.setUseBal(fenToYuan(dto.getUseBal()));
			
			vo.setWthrConn(dto.getWthrConn());
			vo.setRmrk(dto.getRmrk());
			vo.setHid(dto.getHid());
			vo.setHcrId(dto.getHcrId());
			
			vo.setCrtUsrId(dto.getCrtUsrId());
			vo.setCrtTm(dto.getCrtTm());
			vo.setMdfTm(dto.getMdfTm());
			vo.setMdfUsrId(dto.getMdfUsrId());
		}
		return vo;
	}

	/**
	 * VO 转 DTO
	 * @param vo
	 * @return
	 */
	public static CrAstRltvInfoDTO toDTO(CrAstRltvInfoVO vo) {
		CrAstRltvInfoDTO dto = null;
		if (vo != null) {
			dto = new CrAstRltvInfoDTO();
			
			dto.setId(vo.getId());
			dto.setCrId(vo.getCrId());
			dto.setAstId(vo.getAstId());
			dto.setAstNm(vo.getAstNm());
			dto.setPdId(vo.getPdId());
			dto.setPdNm(vo.getPdNm());
			//元转分
			dto.setUseLmt(yuanToFen(vo.getUseLmt()));
			dto.setUseBal(yuanToFen(vo.getUseBal()));
			
			dto.setWthrConn(vo.getWthrConn());
			dto.setRmrk(vo.getRmrk());
			dto.setHid(vo.getHid());
			dto.setHcrId(vo.getHcrId());
			
			dto.setCrtUsrId(vo.getCrtUsrId());
			dto.setCrtTm(vo.getCrtTm());
			dto.setMdfTm(vo.getMdfTm());
			dto.setMdfUsrId(vo.getMdfUsrId());
		}
		return dto;
	}
	
	/**
	 * DTO集合 转 VO集合
	 * @param list
	 * @return
	 */
	public static List<CrAstRltvInfoVO> toVOList(List<CrAstRltvInfoDTO> list) {
		List<CrAstRltvInfoVO>  voList = new ArrayList<CrAstRltvInfoVO>();
		if(CollectionUtils.isNotEmpty(list)){
			for (CrAstRltvInfoDTO po : list) {
				voList.add(toVO(po));
			}
		}
		return voList;
	}
	
	
	
	/**
	 * VO集合 转 DTO集合
	 * @param list
	 * @return
	 */
	public static List<CrAstRltvInfoDTO> toDTOList(List<CrAstRltvInfoVO> list) {
		List<CrAstRltvInfoDTO>  voList = new ArrayList<CrAstRltvInfoDTO>();
		if(CollectionUtils.isNotEmpty(list)){
			for (CrAstRltvInfoVO po : list) {
				voList.add(toDTO(po));
			}
		}
		return voList;
	}
	
	
}
